package com.cdd.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdd.commonutils.R;
import com.cdd.eduservice.entity.EduCourse;
import com.cdd.eduservice.entity.EduTeacher;
import com.cdd.eduservice.service.IEduCourseService;
import com.cdd.eduservice.service.IEduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/front")
@CrossOrigin
public class IndexFront {

    @Autowired
    private IEduCourseService eduCourseService;

    @Autowired
    private IEduTeacherService eduTeacherService;

    @GetMapping("index")
    public R indexFront() {
        // 8门热门课程
        QueryWrapper<EduCourse> wrapperCourse = new QueryWrapper<>();
        wrapperCourse.orderByDesc("id");
        wrapperCourse.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(wrapperCourse);

        // 4个老师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> eduTeachers = eduTeacherService.list(wrapperTeacher);
        return R.ok().data("eduCourses",eduCourses).data("eduTeachers",eduTeachers);
    }
}
